package com.aat.dxfy.thread.demo3;

public class Test2 {

	public static void main(String[] args) {
		final Thread t1=new Thread("t1"){
			@Override
			public void run() {
				int i=0;
				while(true){
					i++;
					System.out.println("t11 count "+i);
					try {
						Thread.sleep(1000);
					} catch (InterruptedException e) {
					}
				}
			}
		};
		
		final Thread t2=new Thread("t2"){
			@Override
			public void run() {
				int i=0;
				while(true){
					i++;
					System.out.println("t22 count "+i);
					try {
						Thread.sleep(1000);
					} catch (InterruptedException e) {
					}
				}
			}
		};
		
		Thread t3=new Thread("t3"){
			@Override
			public void run() {
				int i=0;
				while(true){
					i++;
					//
					if(i==2){
						System.out.println("t1 start ");
						t1.start();
					}
					
					if(i==4){
						System.out.println("t2 start ");
						t2.start();
					}
					
					if(i==6){
						try {
							System.out.println("t1 wait ");
							t1.wait();
						} catch (InterruptedException e) {
							System.err.println("t1.wait() error");
						}
					}
					
					if(i==8){
						try {
							System.out.println("t2 wait 1000 ");
							t2.wait(1000);
						} catch (InterruptedException e) {
							System.err.println("t2.wait(1000) error");
						}
					}
					
					if(i==10){
						System.out.println("t1.notify()");
						t1.notify();
					}
					
					
					if(i==12){
						System.out.println("t2.notify()");
						t2.notify();
					}
					
					if(i==14){
						try {
							System.out.println("t1.join()");
							t1.join();
						} catch (InterruptedException e) {
							System.out.println("t1.join() error"); 
						}
					}
					
					if(i==16){
						System.out.println("t2.interrupt()");
						t2.interrupt();
					}
					//
					try {
						Thread.sleep(1000);
						System.out.println("-----------> "+i);
					} catch (InterruptedException e) {
					}
				}
			}
		};
		t3.start();
	}

}
